<?php

class c_complex_proposal_controller
{
	function c_complex_proposal_controller()
	{
		
	}
	
	function run($args)
	{
		global $mvc;
		
		$date1 = $args['date1'];
		$date2 = $args['date2'];
		$poi = $args['poi'];
		$pois = str_replace(')(', ',', $poi);
		//$pois = '(20)';
		
		print_r($date1);
		
		$sql = 'SELECT * ';
//		$sql .= ', (SELECT count(id) FROM stor_poi WHERE stor_poi.id IN '.$pois.' AND LOCATE(CONCAT("(",stor_poi.id,")"), stor_news.poi))';
		$sql .= ' FROM stor_news';
		$sql .=	' WHERE razdel=1 AND usein_kp=0';
		$sql .= ' AND unix_timestamp(begin) >= unix_timestamp("'.$date1.'")';
		$sql .=	' AND unix_timestamp(end) <= unix_timestamp("'.$date2.'")';
		$sql .=	' AND (SELECT count(id) FROM stor_poi WHERE stor_poi.id IN '.$pois.' AND LOCATE(CONCAT("(",stor_poi.id,")"), stor_news.poi)) > 0';
//		$sql .=	' AND (SELECT id FROM stor_poi WHERE stor_poi.id IN (1,2,3) AND poi.id = stor_news.poi)';
		$sql .=	' ORDER BY date_ ASC';
		//$sql .= ' LIMIT 0,10';
		
		echo $sql;
		
		// [!Storage? &cmd=`get` &name=`news` 
		// &cond=`razdel$eq;'2' AND begin$lt;'{$R.date2}' 
		// AND end$gt;'{$R.date1}' AND usein_kp$eq;'0'` 
		// &order=`date_ DESC` &tpl=`main.new.tpl` &poi=`{$R.poi}` &target=`pager`!]



		//[!Storage? &cmd=`get` &name=`news` &cond=`razdel$eq;'1' AND begin$lt;'{$R.date2}' AND end$gt;'{$R.date1}' AND usein_kp$eq;'0'` &order=`date_ DESC` &tpl=`main.sale.templ` &poi=`{$R.poi}` &target=`pager`!]		
		
		//$taxonomy->get_data('SELECT * FROM POI,NEWS,LINKS WHERE POI.id=links.id {ptable} WHERE {linkage} AND {pid}='
		
		//$sql = 'SELECT * FROM stor_news limit 0,10';
		return '<pre>'.print_r($mvc->db->get_data($sql), true).'</pre>';
		
		//return 'yaya';
	}
}

?>
